package com.zhiyou100.springbootmybatisplus.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@AllArgsConstructor
@ToString
@NoArgsConstructor
public class Result {
    private int code;
    private Long total;
    private String msg;
    private  Object data;

    public static Result fail(){
        return result(400,"失败",0L,null);
    }
    // 失败响应（带消息参数）
    public static Result fail(String message) {
        return result(400, message, 0L, null);
    }
    public static Result suc(){
        return result(200,"成功",0L,null);
    }
    // 成功，有数据，无总数时
    public static Result suc(Object data) {
        return new Result(200, null,"成功",  data); // 设置 total 为 null
    }

    // 成功，有数据和总数时
    public static Result suc(Object data, Long total) {
        return new Result(200,  total,"成功", data);
    }
    public static Result result(int code,String msg,Long total,Object data){
        Result res = new Result();
        res.setData(data);
        res.setCode(code);
        res.setTotal(total);
        res.setMsg(msg);
        return res;
    }


}
